package cl.ccs.migracionbcmc.validators;

import cl.ccs.migracionbcmc.util.Rut;
import cl.ccs.migracionbcmc.validators.exception.ValidatorException;


public class RutValidator {
    
    private Rut rut;
    private String validationErrorMessage;
    private boolean errorHappen;
    
    public RutValidator(String strRut) {
        super();
        setErrorHappen(false);
        setValidationErrorMessage("");
        try{
            setRut(new Rut(strRut));
        }
        catch(ValidatorException ve) {
            setErrorHappen(true);
            setValidationErrorMessage(ve.getMessage());
            setRut(null);
        }
    }

    private void setRut(Rut rut) {
        this.rut = rut;
    }

    public Rut getRut() {
        return rut;
    }

    private void setValidationErrorMessage(String validationErrorMessage) {
        this.validationErrorMessage = validationErrorMessage;
    }

    public String getValidationErrorMessage() {
        return validationErrorMessage;
    }

    private void setErrorHappen(boolean errorHappen) {
        this.errorHappen = errorHappen;
    }

    private boolean isErrorHappen() {
        return errorHappen;
    }
    
    public boolean isValid() {
        return !isErrorHappen();
    }
}
